# include<iostream>
# include<vector>
# include"NewtonFormula.h"
# include"Function.h"

using namespace::std;

/**
* @brief 一个仿函数类，用于计算 f(x)
* 
*/
class func : public Function
{
public:
    double operator() (const double & _x) const
    {
        return (1 / (1 + _x * _x));
    }
};

/**
* @brief 生成[-5,5]上对应数量的等距插值点
* 
*/
vector<double> CreatPoint(int n)
{
    vector<double> point;
    double xi = 0;
    for (int i = 0; i <= n; i++)
    {
        xi = -5 + 10.0 * i / n;
        point.push_back(xi);
    }
    return point;
}

/**
* @brief 打印对应的向量
* 
*/
void PrintVector(vector<double> vec)
{
    for (int i = 0; i < vec.size(); i++)
    {
        cout << vec[i] << " ";
    }
    cout << endl;
}

int main()
{
    func f;

    // 分为不同的 n 计算对应的牛顿插值多项式
    for (int n = 2; n <= 8; n += 2)
    {
        cout << "n = " << n << endl;
        vector<double> point(CreatPoint(n));
        PrintVector(point);
        NewtonFormula Solver(f, point);
        Solver.PrintPol();
        Solver.PrintPolCoff();
    }

    return 0;
}